package com.yzc.Authentication;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

public class JwtAuthenticationToken implements Authentication {

    private final String userId; // 用户 ID
    private final String username; // 用户名
    private final Collection<? extends GrantedAuthority> authorities; // 权限集合
    private boolean authenticated; // 是否已认证

    public JwtAuthenticationToken(String userId, String username, Collection<? extends GrantedAuthority> authorities) {
        this.userId = userId;
        this.username = username;
        this.authorities = authorities;
        this.authenticated = true; // 默认已认证
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public Object getCredentials() {
        return null; // 不需要凭证
    }

    @Override
    public Object getDetails() {
        return null; // 不需要额外信息
    }

    @Override
    public Object getPrincipal() {
        return this; // 返回当前对象
    }

    @Override
    public boolean isAuthenticated() {
        return authenticated;
    }

    @Override
    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
        this.authenticated = isAuthenticated;
    }

    @Override
    public String getName() {
        return username; // 返回用户名
    }

    public String getUserId() {
        return userId; // 返回用户 ID
    }

    public String getUsername() {
        return username; // 返回用户名
    }
}